<?php
/**
 * admin service file Created by PhpStorm.
 * User: yang
 * Date: 2020/04/27
 */

namespace Common\Service;

use Common\Repository\PublicRepository;

class PublicService
{
    /**
     * 检测表字段数据的唯一性
     * @param array $data
     * @return array
     */
    public function checkOnly($data = [])
    {
        try {
            $id = $data['id'] ?? null;
            $where[$data['key']] = $data['val'];

            $result = PublicRepository::countNum($data['table'], $where, $id);
            if ($result > 0) {
                return hello_error('该数据已存在，请重新输入！');
            }

            return hello_success('OK');
        } catch (\Exception $exception) {
            return hello_error('失败！', $exception->getMessage());
        }
    }

}